package com.zzb.servlet.company;

import com.alibaba.fastjson.JSONObject;
import com.zzb.DTO.ResultDTO;
import com.zzb.VO.CompanyVO;
import com.zzb.service.CompanyService;
import com.zzb.service.impl.CompanyServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet("/back/company/id")
public class CompanyFindByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        //得到前端数据
        String id = req.getParameter("id");



        //对前端数据进行封装
        CompanyVO companyVO = new CompanyVO();
        companyVO.setId(Integer.valueOf(id));


        //调用服务逻辑
        CompanyService companyService = new CompanyServiceImpl();

        //得到返回值
        ResultDTO resultDTO = companyService.findById(companyVO);

        //将数据响应给前端
        resp.getWriter().println(JSONObject.toJSONString(resultDTO));
    }
}
